#include  <iostream>
#include  <list>

using namespace std;

class A
{
    public:
        A( )
        {
            number = 1;
        }
        virtual void prepareBeforePrint()
        {
            number = 10;
        }
        virtual int getNumber( ) const
        {
            return number;
        }
        virtual ostream& print( ostream& os) const
        {
            return os << number << endl;
        }
        virtual bool operator==( const A& a)
        {
            return (a.number == this->number);
        }
    protected:
        virtual void setNumber( int i)
        {
            number = i;
        }
    private:
        int number;
};

class B : public A
{
        public:
            virtual void prepareBeforePrint( )
            {
                setNumber( 100);
            }
            virtual ostream& print( ostream& os) const
            {
                return ( A::print( os) << "B")<< endl;;
            }
}; 

class remover
{
    public:
        remover( int id)
        {
            this->id =id;
        }
        virtual bool operator()( const A* a)
        {
            if ( a->getNumber( ) == id)
            {
                delete[] a;
                return true;
            }
            return false;
        }
    private:
        int id;
};

ostream& operator<<( ostream& os, A& a)
{
    return a.print( os);
};

int main( )
{
    A a, *a1;
    B b;
    list< A*> db;
    remover rm( 1);
   
    db.push_back( new A( ));
    a1 = db.back( );
    db.remove_if( rm);
    a.prepareBeforePrint( );
    b.prepareBeforePrint( );
    cout << a << b << endl;
}
